<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        display: flex;
        width: 500px;
        height: 30px;
      }
      .arr {
        background: url(./images/mess.png) no-repeat left center;
      }
      .box p {
        padding-left: 20px;
        padding-top: 5px;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <input type="text" />
      <p class="arr">请输入6-16位密码</p>
    </div>
    <script>
      //获取元素
      var int = document.querySelector('.box input');
      var pp = document.querySelector('.box p');
      //事件类型
      int.onblur = function () {
        //事件代码
        if (this.value.length < 6 || this.value.length > 16) {
          pp.style.background = 'url(./images/wrong.png) no-repeat left center';
          pp.innerText = '密码验证失败';
        } else {
          pp.style.background = 'url(./images/right.png) no-repeat left center';

          pp.innerText = '密码验证成功';
        }
      };
    </script>
  </body>
</html>
